package com.dx.as.config.preference;

import android.content.Context;
import android.content.SharedPreferences;

import com.dx.as.JWCache;

/**
 * Created by hzxuwen on 2015/4/13.
 */
public class Preferences {
    private static final String KEY_USER_ACCOUNT = "account";
    private static final String KEY_USER_TOKEN = "token";
    private static final String KEY_USER_SHOW_NAME = "show_name";
    private static final String KEY_IM_ACCOUNT = "im_account";
    private static final String KEY_USER_PERFECT = "perfect";

    public static void saveUserAccount(String account) {
        saveString(KEY_USER_ACCOUNT, account);
    }

    public static String getUserAccount() {
        return getString(KEY_USER_ACCOUNT);
    }

    public static void saveIMName(String showName){
        saveString(KEY_USER_SHOW_NAME,showName);
    }
    public static String getIMName(){
        return getString(KEY_USER_SHOW_NAME);
    }

    public static void saveIMAccount(int account){
        saveInteger(KEY_IM_ACCOUNT,account);
    }

    public static int getIMAccount(){
        return getInteger(KEY_IM_ACCOUNT);
    }

    public static void saveUserToken(String token) {
        saveString(KEY_USER_TOKEN, token);
    }

    public static void savePerfect(int perfect){
        saveInteger(KEY_USER_PERFECT,perfect);
    }

    public static int getPerfect(){
        return getInteger(KEY_USER_PERFECT);
    }

    public static String getUserToken() {
        return getString(KEY_USER_TOKEN);
    }

    private static void saveString(String key, String value) {
        SharedPreferences.Editor editor = getSharedPreferences().edit();
        editor.putString(key, value);
        editor.commit();
    }

    private static void saveInteger(String key, int value) {
        SharedPreferences.Editor editor = getSharedPreferences().edit();
        editor.putInt(key, value);
        editor.commit();
    }

    private static String getString(String key) {
        return getSharedPreferences().getString(key, null);
    }

    private static int getInteger(String key){
        return getSharedPreferences().getInt(key,0);
    }

    static SharedPreferences getSharedPreferences() {
        return JWCache.getContext().getSharedPreferences("Demo", Context.MODE_PRIVATE);
    }
}
